<?php require_once('../Connections/agriculture.php'); ?>
<?php

mysql_select_db($database_agriculture, $agriculture);
$querySql="select * from video where video_id=".$_GET["id"];
$queryResult=mysql_query($querySql,$agriculture) or die(mysql_error());
$row_queryResult=mysql_fetch_assoc($queryResult);
?>


<p><a href="admin.php">返回</a></p>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<p><label>标题 
    <input type="text" name="textfield2" value="<?php echo $row_queryResult["video_title"];?>"> </label></p>
<p><label>类型 <input type="text" name="textfield3" value="<?php echo $row_queryResult["video_class"];?>"> </label></p>
<p><label>发布时间 <input type="text" name="textfield5" value="<?php echo $row_queryResult["video_time"];?>"> </label></p>
<p><label>作物名称 <input type="text" name="textfield6" value="<?php echo $row_queryResult["video_name"];?>"> </label></p>
<p><label>生长时期 <input type="text" name="textfield7" value="<?php echo $row_queryResult["video_period"];?>"> </label></p>
<p><label>说明信息 <textarea  name="textarea" ><?php echo $row_queryResult["video_information"];?></textarea> 
</label></p>
<p>视频 <label> <input type="file" name="file"> </label>
(仅支持.flv格式视频文件)</p>
<p><label> <input type="submit" name="Submit" value="提交" onclick="check(form1)" > </label> <label>
<input type="reset" name="Submit2" value="重置"> </label></p>
</form>

<?php
if (is_uploaded_file ( $_FILES ['file'] ['tmp_name'] )) {
	$file = $_FILES ["file"];
	$tmp_name = $file ["tmp_name"];
	$upFileName = "flash/" . $row_queryResult["video_id"] . ".flv";
	echo $file['name'];
	if(eregi("flv$", $file['name'])){
	$result = move_uploaded_file ( $tmp_name, $upFileName );
	}
} else {
	$upFileName = $row_queryResult["video_other"];
}

mysql_free_result($queryResult);

if($_POST["textfield2"]){
$id=$_GET["id"];
$title=$_POST["textfield2"];
$class=$_POST["textfield3"];
$time=$_POST["textfield5"];
$name=$_POST["textfield6"];
$period=$_POST["textfield7"];
$information=$_POST["textarea"];

$updateSql="update video set video_title='".$title."', video_class='".$class."', video_publisher='".$_SESSION["user"]."', video_time='".$name."', video_period='".$period."', video_information='".$information."', video_other='".$upFileName."' where video_id=".$id;

$updateResult=mysql_query($updateSql,$agriculture) or die(mysql_error());
if($updateResult&&$result){
	echo '<script language="javascript">alert("操作成功!");window.location.href="admin.php";</script>';
}
//mysql_free_result($updateResult);;
}
?>

<script language="javascript">
function isEmpty(str){
 for(var i=0;i<str.length;i++){
  if(str.charAt(i)!==" "){
    return false;
  }
 }
 return true;
}
function check(form){
 var fileName = form.file.value;
 if(isEmpty(fileName)){
    alert("请选择文件");
    form.file.focus();
    return false;
 }
 //lastIndexOf如果没有搜索到则返回为-1
    if(fileName.lastIndexOf(".")!=-1)
 {
    var fileType = (fileName.substring(fileName.lastIndexOf(".")+1,fileName.length)).toLowerCase();
       var suppotFile = new Array();
    suppotFile[0] = "flv";
    for(var i =0;i<suppotFile.length;i++){
       if(suppotFile[i]==fileType){
     return true;
    }else{
   continue;
    }
  }
  alert("不支持的文件类型"+fileType);
  return false;
 }else
 {
  alert("文件只支持flv格式");
 }
}
</script>
